#if !defined(AFX_MAINORDERPANEL_H__85E07A36_7F5E_41B8_B634_5D3DACF755B5__INCLUDED_)
#define AFX_MAINORDERPANEL_H__85E07A36_7F5E_41B8_B634_5D3DACF755B5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MainOrderPanel.h : header file
//
#include "CurPriceGrid.h"
#include "OrderPanelGrid.h"
#include "OrderStateGrid.h"
#include "TickTableGrid.h"
#include "CurPriceManager.h"
#include "resource.h"
#include "ResizeDlg.h"
#include "CurPriceInfo.h"
#include "afxwin.h"
#include "SymbolManager.h"
#include "AccountManager.h"
#include "OrderManager.h"
#include "ResizableDialog.h"
#include "FillGrid.h"
#include "OptionGrid.h"
#include "GridCountDif.h"
#include "afxcmn.h"
#include "TotalGrid.h"
#include "MiniJangoDlg.h"

#include "SymbolEventSink.h"


#include <vector>
#include <string>
using namespace std;

typedef vector<CWnd*> WndList;
typedef vector<CWnd*> VisibleList;
/////////////////////////////////////////////////////////////////////////////
// CMainOrderPanel dialog
class CPositionInfo;
class CFilledOrdersDlg;
class CEventManager;
class CGomSymbolReceiver;
class CMainOrderPanel : public CResizableDialog
{
// Construction
public:
	void RequestChartData();
	void ResizeControl();
	void ResizeControl(int a_TotalWidth);
	bool m_Extend;
	void LayoutCells();
	bool m_Visible;
	CMainOrderPanel(CWnd* pParent = NULL);   // standard constructor

	IGxServer*          m_Server;
	CGomSymbolReceiver* m_GomSym;

	VisibleList     m_VisibleWndList;
	WndList         m_MoveWndList;
	COrderPanelGrid m_OrderPanelGrid;
	COrderStateGrid m_OrderStateGrid;
	CTickTableGrid  m_TickTableGrid;
	CCurPriceGrid   m_CurPriceGrid;
	CFillGrid       m_FillGrid;
	COptionGrid     m_OptionGrid;
	CGridCountDif   m_CountDifGrid;
	CTotalGrid      m_TotalGrid;

	//CCurPriceManager m_CurPriceMgr;

	CEventManager* m_pEventMgr;
	//vectorSymBolManager m_SymbolMgrList;
	CSymbolManager* m_SymbolMgr;
	CSymbolInfo* m_CurSymbol;
	CAccountManager* m_AccountMgr;
	CAccountInfo* m_CurAccount;
	CPositionInfo* m_CurPosition;

	COrderManager* m_OrderManager;

	CFilledOrdersDlg* m_FilledOrdersDlg;

	string m_NearFutureCode;
	int    m_OrderRowHeight;
	int    m_OrderColWidth;

	bool   m_ShowCount;
	bool   m_OrderByMouseOn;

	UINT Timeval;

	void ShowLeftControls(bool a_Show);
	bool m_ShowLeftControl;
	void ResetTopVal(double a_TopVal);
	void AddSymbolToCombo(string a_String);
	void InitOptionMonth();

	BOOL m_bInit;

	void UpdateOrderInfo();
	void SetJago();
	void SetJago(CPositionInfo* a_CurPosi);
	void PutOrder(CString a_Val, IPositionType a_PositionType);
	void CancelOrder(CString a_Val, IPositionType a_PositionType);
	void ModifyOrder(CString a_Val, CString a_NewVal, IPositionType a_PositionType);

	void CancelOrder(CString a_Val, IPositionType a_PositionType, CString a_Price);
	void ModifyOrder(CString a_Val, CString a_NewVal, IPositionType a_PositionType, CString a_OldVal);

	void ShowOrders();
	void ShowFilledOrders();

	void ShowCurValues();

	void RefreshPosition(CPositionInfo* a_Posi);
	void RefreshAccount(CAccountInfo* a_Acc);

	void SetOptionMonthByIndex(int a_Index);
	//void ChangeFutureSymbol(CString a_SymbolCode);
	void RefreshOrderPanelGrid();
	void ChangeOptionSymbol(CString a_OptionCode);

	void SetOrderAmountText(CString a_Text);

	void OnPriceChanged(bool a_RealTime = true);
	void OnQuoteChanged();
	void OnTickChanged();
	void RefreshPosition();

	COrderInfo* OnNewOrder(lpExpTr0988O_sub a_Order);
	void ShowNewOrder(COrderInfo* a_NewOrder);
	void ShowNewOrder(CPositionInfo* a_Posi, COrderInfo* a_NewOrder, COrderInfo* a_PrevOrder);
	void ShowConfirmOrder(COrderInfo* a_ConfirmOrder);
	CPositionInfo* AddPosition();
	string GetProductName(string a_Code);
	string MakeTitle(string a_Code);

	HMODULE		hIns;
	long OnSvrRead(WPARAM wParam, LPARAM lParam);
	
	long OnSvrSise(WPARAM wParam, LPARAM lParam);
	long OnSvrHoga(WPARAM wParam, LPARAM lParam);
	long OnSvrJumun(WPARAM wParam, LPARAM lParam);
	long OnSvrJango(WPARAM wParam, LPARAM lParam);
	long OnSvrAccountJango(WPARAM wParam, LPARAM lParam);
	long OnSvrRealJumun(WPARAM wParam, LPARAM lParam);
	long OnSvrRealSise(WPARAM wParam, LPARAM lParam);
	long OnSvrRealHoga(WPARAM wParam, LPARAM lParam);
	long OnSvrRealTick(WPARAM wParam, LPARAM lParam);
	long OnSvrRealServerTime(WPARAM wParam, LPARAM lParam);

	long OnSvrNewOrder(WPARAM wParam, LPARAM lParam);
	long OnSvrModifyOrder(WPARAM wParam, LPARAM lParam);
	long OnSvrCancelOrder(WPARAM wParam, LPARAM lParam);
	long OnTradeState(WPARAM wParam, LPARAM lParam);
	long OnCenterMessage(WPARAM wParam, LPARAM lParam);



	void OnUpdateMaxOrder(string a_Acc, string a_Sym, string a_Mmgb, string a_MaxLiqOrder, string a_MaxOrder);

	void ResetAutoRequestJisu(string a_FullCode);
	void SetAutoRequestJisu(string a_FullCode);
	
	void ResetAutoRequestAccount(string a_AccCode);
	void SetAutoRequestAccount(string a_AccCode);

	void CheckLossCut();
	string GetFullCode(string a_ShortCode);

	void ClearVisibleQtyCntRow();

	void SetCurrentValue(bool a_RealTime = true);
	void SetCurrentHoga(bool a_RealTime = true);
	void SetCurrentOrders(bool a_RealTime = true);

	void CompleteUnfilledOrders();
	void CompleteFilledOrders();
	void OnRealSise();
	void OnCompleteJango();
	void OnComleteSise();

private:
	//void LoadUserInfo();

	// KR Dll Module Instance Handle.
	/*
	BOOL        m_bKRDllLoad;
	BOOL        m_bKRLogin;
	string      m_KRID;
	string      m_KRPassWord;


	void LoadKRDll();
	void LoginToKR();
	*/

	// KR Server Response

	void SelectAccountByIndex(int a_Index);
	CFont m_CtrlFont;
	CString m_strCode;

	CString m_strAccount;


	void InitAccount();
	void InitSymbol();

	void PutOrder(CString a_Code, CString pType, CString OType, long Qty, double OrderP, CString Ocls, long OrdNum);



// Dialog Data
	//{{AFX_DATA(CMainOrderPanel)
	enum { IDD = IDD_MAIN_ORDER };
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMainOrderPanel)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
		
	int m_CurRow;
	void ShowCenterValues();
	// Generated message map functions
	//{{AFX_MSG(CMainOrderPanel)
	virtual BOOL OnInitDialog();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnClose();
	afx_msg void OnBtnExpandR();
	afx_msg void OnBtnExpandL();
	//afx_msg LRESULT OnCurPriceUpdated(WPARAM wParam, LPARAM lParam);
	//afx_msg LRESULT OnQuoteUpdated(WPARAM wParam, LPARAM lParam);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
	virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);

	void RepositionCurVal();


	void UpdateCtrl();

	void MoveControls(int a_X, int a_Y);
public:
	afx_msg void OnBnClickedBtnCenter();
	CComboBox m_ComboAccount;
	CComboBox m_ComboProduct;
	afx_msg void OnSelchangeComboAccount();
	afx_msg void OnSelchangeComboProduct();
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg void OnSelchangeComboOptionMonths();
	CComboBox m_ComboOptionMonths;
	//CButton m_CheckReserveTick;
	//CButton m_CheckTick;
	CStatic m_StaticOptionMonth;
//	CEdit m_EditTick;
	bool m_GotUnfilledOrders;
	bool m_GotJango;

	bool m_cbStopQty;
	bool m_cbTickLossCut;
	bool m_cbTickProfitCut;

	int m_edStopQty;
	int m_edTickLossCut;
	int m_edTickProfitCut;
	CButton m_checkLossCut;
	CButton m_checkProfitCut;
	CEdit m_editLossCut;
	CEdit m_editProfitCut;
	CEdit m_EditTick;
	afx_msg void OnBnClickedCheckProfitcut();
	afx_msg void OnEnChangeEditProfitcut();
	afx_msg void OnBnClickedCheckLosscut();
	afx_msg void OnEnChangeEditLosscut();
	CButton m_BtnFuture;
	afx_msg void OnBnClickedBtnFuture();
//	CSpinButtonCtrl m_SpinLossCut;
//	CSpinButtonCtrl m_SpinProfitCut;
//	CStatic m_StaticOption;
	CButton m_BtnCenter;
	CButton m_BtnMaxOrder;
	CSpinButtonCtrl m_SpinLossCut;
	CSpinButtonCtrl m_SpinProfitCut;
	afx_msg void OnBnClickedButtonMaxOrder();
	afx_msg void OnStnClickedCurPrice();
	CButton m_CheckMainCnt;
	afx_msg void OnBnClickedCheckMainCnt();
	CButton m_BtnFilledOrders;
	afx_msg void OnBnClickedBtnFilledOrders();
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MAINORDERPANEL_H__85E07A36_7F5E_41B8_B634_5D3DACF755B5__INCLUDED_)
